
clear

use "zim_r1_data.dta", clear
gen round = "r1"
ren casenumb respno

rename *, lower

************************
***   Demographic    ***
************************

gen surveyor_origin = .
gen surveyor_gov = .
gen surveyor_pol = .

label var surveyor_gov "Government sent surveyor"
label var surveyor_pol "Political party/politician sent surveyor"

* Demographic

gen age = q110 if q110 < 104 & q110 >= 18
gen year_birth = 1999-age

gen schooling = q112 if q112 < 10 & q112 > -1
recode schooling (0/1=0) (2=1) (3=2) (4=3) (5=4) (6/9=5)

gen urban_rural = q154
gen urban = urban_rural == 2

gen gender = q125
gen male = gender == 2

gen race = q126
keep if race == 1

decode q111, gen(language)
gen tribe = .

gen ndebele = (strpos(language, "Ndebele")>0) if language!="" & strpos(language, "Missing")==0
gen shona = (strpos(language,"Shona")>0 | strpos(language,"Bocha")>0 | strpos(language,"Chewa")>0 | strpos(language,"Kalanga")>0 | strpos(language,"Karanga")>0 | strpos(language,"Korekore")>0 | strpos(language,"Manyika")>0 | strpos(language,"Nyanja")>0 | strpos(language,"Ndau")>0 | strpos(language,"Sezuru")>0 | strpos(language,"Zezuru")>0) if language!="" & strpos(language, "Missing")==0
gen other = (ndebele ==0 & shona == 0)


label var age "Age"
label var year_birth "Birth year"
label var schooling "Schooling"
label var urban "Urban"
label var male "Male"
label var language "Language"
label var tribe "Tribe"
label var ndebele "Ndebele tribe"
label var shona "Shona group tribes"
label var other "Other tribes"


******************************
***   Economic variables   ***
******************************

* Economic 

gen no_food = q13a-1 if q13a < 5
gen no_water = q13e-1 if q13e < 5
gen no_meds = q13c-1 if q13c < 5
gen no_fuel = q13h-1 if q13h < 5
gen no_cash = q13d-1 if q13d < 5

foreach var of varlist no_food-no_cash {
	replace `var' = . if `var' >= 8 | `var' < 0
}

label var no_food "Go without food"
label var no_water "Go without water"
label var no_meds "Go without medicine"
label var no_fuel "Go without fuel"
label var no_cash "No cash"



* Assets

gen owns_radio = .
gen owns_tv = .
gen owns_bike = .
gen owns_vehicle = .
gen owns_mobile = .

foreach var of varlist owns_radio-owns_mobile {
	replace `var' = . if `var' >= 9 | `var' < 0
}

label var owns_radio "Owns radio"
label var owns_tv "Owns TV"
label var owns_bike "Owns bicycle"
label var owns_vehicle "Owns motor vehicle"
label var owns_mobile "Owns mobile phone"


* Employment

gen empl_stat = q113-1
gen look_for_job = (empl_stat == 1) if empl_stat < 6 & empl_stat >= 0
gen part_time = (empl_stat == 2 | empl_stat == 3) if empl_stat < 6 & empl_stat >= 0
gen full_time = (empl_stat == 4 | empl_stat == 5) if empl_stat < 6 & empl_stat >= 0

label var look_for_job "No job and looking for job"
label var part_time "Part time job"
label var full_time "Full time job"


*****************************************
***   Political Engagement Variables  ***
*****************************************

* Local engagement

gen assoc_rel = .
gen assoc_comm = .
gen raise_issue = .

foreach var of varlist assoc_rel-raise_issue {
	replace `var' = . if `var' >= 9 | `var' == -1
}

label var assoc_rel "Member of religious association"
label var assoc_comm "Member of community association"
label var raise_issue "Join others in raising issues"


* Political engagement

gen att_rally = q90b-1 if q90b < 6
gen att_pol_meeting = .
gen persuade_others = .
gen work_for_cand = q90c-1 if q90c < 6
gen int_pub_aff = q45-1 if q45 < 5
gen disc_pol = q44-1 if q44 < 4

foreach var of varlist att_rally - disc_pol {
	tab `var'
	replace `var' = . if `var' >= 9 | `var' == -1
}

recode att_rally (0/2=1) (3/4=0)
recode work_for_cand (0/2=1) (3/4=0)
recode disc_pol (0=2) (2=0)

label var att_rally "Attend campaign rally"
label var att_pol_meeting "Attend campaign meeting"
label var persuade_others "Persuade others to vote for party"
label var work_for_cand "Worked for candidate"
label var int_pub_aff "Interested in public affairs"
label var disc_pol "Discusses politics"

gen req_action = .
gen contact_med = .
gen contact_official = .
gen refuse_tax = .
gen att_demo = q92a-1 if q92a < 6

foreach var of varlist req_action-att_demo {
	tab `var'
	replace `var' = . if `var' >= 9 | `var' == -1
}

recode att_demo (4=0) (3=1) (1=3) (0=4)


label var req_action "Join others to request gov action"
label var contact_med "Contact media for change"
label var contact_official "Contact officials for change"
label var refuse_tax "Refuse to pay tax or fee to gov"
label var att_demo "Attend demonstration"


* Consuming political news

gen radio = q42a-1
gen tv = q42b-1
gen newspapers = q42c-1
gen internet = .
gen social_media = .


label var radio "Listens to radio for news"
label var tv "Watches TV for news"
label var newspapers "Reads newspaper for news"
label var internet "Uses internet for news"
label var social_media "Uses social media for news"


foreach var of varlist radio-social_media {
	tab `var'
	replace `var' = . if `var' >= 5 | `var' == -1
	recode `var' (4=0) (3=1) (1=3) (0=4)
}

* Voting

gen registered = .

gen voted = q89 == 3
replace voted = . if q89 >= 5

label var registered "Registered to vote"
label var voted "Voted in elections"


****************************************************
***   Understanding of democratic institutions   ***
****************************************************

* Democracy

gen elec_free = q49-1 if q49 < 5

gen hold_accountable = .
gen pro_elections = .
gen parties_needed = .
gen opp_hold_acc = .
gen media_hold_acc = .
gen parl_laws = .
gen pres_obey_laws = .
gen two_term = .

foreach var of varlist hold_accountable-two_term {
	recode `var' (1=0) (2=1) (5=2) (9/98=.) (-1=.)
	tab1 `var'
}

foreach var of varlist pro_elections opp_hold_acc media_hold_acc parl_laws two_term {
	recode `var' (4=0) (3=1) (2=2) (1=3) (0=4)
}


label var elec_free "Freeness and fairness of last elections"

label var hold_accountable "Gov produce results quickly vs. citizens hold gov accountable"
label var pro_elections "Don't elect vs. elect officials"
label var parties_needed "Parties generate chaos vs. parties necessary"
label var opp_hold_acc "Opposition work with gov vs. opposition act as watchdog"
label var media_hold_acc "Media avoid negative reporting vs. media checks gov"
label var parl_laws "Pres makes law vs. parl makes laws"
label var pres_obey_laws "Pres doesn't need to obey laws vs. pres must obey laws"
label var two_term "No term limit vs. two term limit"



********************************
***   Quality of democracy   ***
********************************

gen democracy = q104-1 if q104 < 5
recode democracy (0=3) (2=1) (1=2) (3=0)

gen sat_demo = q105-1 if q105 < 6
recode sat_demo (0=4) (1=3) (3=1) (4=0)

gen media_abuse_freedom = .
gen party_comp_confl = .

gen parl_accountable = .
gen remove_leaders = .

gen careful_say = .

gen votes_fair = .
gen bribed = .
gen real_choice = .
gen threatened = .
gen fear_intimidation = .

gen freedom_say = .
gen freedom_join = .
gen freedom_choose = .



* Authoritarian preferences

gen reject_one_party = q52-1 if q52 < 6
gen reject_military = q54-1 if q54 < 6
gen reject_one_man = q55-1 if q55 < 6


foreach var of varlist elec_free-reject_one_man {
	replace `var' = . if `var' >= 7 | `var' <= -1
	tab `var'
}

foreach var of varlist reject_* {
	recode `var' (0=4) (1=3) (2=2) (3=1) (4=0)
}

label var democracy "Zimbabwe is a democracy"
label var sat_demo "Satisfied with democracy in Zimbabwe"
label var media_abuse_freedom "Media abuses its freedoms"
label var party_comp_confl "Party competition leads to conflict"

label var parl_accountable "Elections ensures citizens' views are reflected in parl"
label var remove_leaders "Elections allows citizens to remove bad leaders"

label var reject_one_party "Reject single party rule"
label var reject_military "Reject military rule"
label var reject_one_man "Reject one man rule"

label var freedom_say "Free to say what you think"
label var freedom_join "Free to join any political organization"
label var freedom_choose "Free to choose who to vote for"


* Views about government

gen trust_pres = q64-1 if q64 < 5
gen trust_mp =  q68-1 if q68 < 5
gen trust_ec = q77d-1 if q77d < 5
gen trust_tax = .
gen trust_lg =  q73-1 if q73 < 5
gen trust_inc = .
gen trust_opp = .
gen trust_police = q77b-1 if q77b < 5
gen trust_army = q77a-1 if q77a < 5
gen trust_courts = q77c-1 if q77c < 5
gen trust_trad = .
gen trust_relig = .

foreach var of varlist trust_pres-trust_relig {
	replace `var' = . if `var' >= 8 | `var' < 0
	tab `var'
}

label var trust_pres "Trust president"
label var trust_mp "Trust MP"
label var trust_ec "Trust Electoral Commission"
label var trust_tax "Trust tax office"
label var trust_lg "Trust LG"
label var trust_inc "Trust incumbent party"
label var trust_opp "Trust opposition party"
label var trust_police "Trust police"
label var trust_army "Trust army"
label var trust_courts "Trust courts and dept of justice"
label var trust_trad "Trust traditional leaders"
label var trust_relig "Trust religious leaders"


* Public goods

gen post_office = q159 == 1 if q159 <= 2
gen school = q160 == 1 if q160 <= 2 
gen police_station = q161 == 1 if q161 <= 2 
gen transport = q162 == 1 if q162 <= 2 
gen electricity = q163 == 1 if q163 <= 2 
gen piped_water = q164 == 1 if q164 <= 2 
gen sewage = q165 == 1 if q165 <= 2
gen railway = q166 == 1 if q166 <= 2
gen health_clinic = q167 == 1 if q167 <= 2
gen rec_facilities = q168 == 1 if q168 <= 2
gen placesof_worship = q169 == 1 if q169 <= 2
gen townhalls = q170 == 1 if q170 <= 2
gen petrol_station = q171 == 1 if q171 <= 2
gen bottle_store = q172 == 1 if q172 <= 2
gen supermarket = q173 == 1 if q173 <= 2
gen cafes = q174 == 1 if q174 <= 2
gen market_stalls = q175 == 1 if q175 <= 2
gen police_vehicles = q176 == 1 if q176 <= 2
gen soldiers_army = q177 == 1 if q177 <= 2
gen pavement = q178 == 1 if q178 <= 2


*************************
***   Final cleanup   ***
*************************

keep round respno province district v12 surveyor_gov - pavement

drop tribe language

tostring v12, g(dateintr)
replace dateintr = "" if dateintr == "99"


foreach var of varlist surveyor_gov - pavement {
	disp "`var'"
	count if (`var' < -1 | `var' >= 8) & `var' != .
}

duplicates drop round respno, force

replace dateintr = subinstr(dateintr, "1999", "", .)
gen month = substr(dateintr, 1, 2)
gen day = substr(dateintr, 3, 4)
destring month, replace
gen year = 1999
